FROM nginx:stable-alpine

MAINTAINER koma <komazhang@foxmail.com>

ENV fpm_www_conf /etc/php7/php-fpm.d/www.conf
ENV fpm_main_conf /etc/php7/php-fpm.conf
ENV document_root /var/www/html

RUN echo 'http://mirrors.aliyun.com/alpine/edge/main/'      >  /etc/apk/repositories && \
    echo 'http://mirrors.aliyun.com/alpine/edge/community/' >> /etc/apk/repositories

#set timezone
RUN apk update && apk add tzdata && \
    cp /usr/share/zoneinfo/Asia/Chongqing /etc/localtime && \
    apk del tzdata

RUN apk update && \
    apk add --no-cache bash \
    wget \
    curl \
    supervisor \
    php7-fpm \
    php7-common \
    php7-xdebug \ 
    php7-pdo \
    php7-pdo_mysql \
    php7-mysqlnd \
    php7-mysqli \
    php7-mcrypt \
    php7-mbstring \
    php7-ctype \
    php7-zlib \
    php7-gd \
    php7-exif \
    php7-intl \
    php7-sqlite3 \
    php7-pdo_pgsql \
    php7-pgsql \
    php7-xml \
    php7-xsl \
    php7-curl \
    php7-openssl \
    php7-iconv \
    php7-json \
    php7-phar \
    php7-soap \
    php7-dom \
    php7-zip \
    php7-session \
    php7-imap \
    php7-opcache \
    git

RUN sed -i \
        -e "s/;daemonize\s*=\s*yes/daemonize = no/g" \
        #-e "s/;error_log\s*=\s*log\/php7\/error.log/error_log = log\/php7\/error.log/g" \
        #-e "s/;log_level\s*=\s*notice/log_level = debug/g" \
        ${fpm_main_conf}

RUN sed -i \
        -e "s/listen = 127.0.0.1:9000/listen = \/var\/run\/php-fpm.sock/g" \
        -e "s/^user\s*=\s*nobody/user = nginx/g" \
        -e "s/^group\s*=\s*nobody/group = nginx/g" \
        -e "s/;listen.owner\s*=\s*nobody/listen.owner = nginx/g" \
        -e "s/;listen.group\s*=\s*nobody/listen.group = nginx/g" \
        ${fpm_www_conf}

#create dir
RUN rm -rf ${document_root}/* && mkdir -p ${document_root}

#copy nginx config
RUN rm -rf /etc/nginx/nginx.conf
RUN rm -rf /etc/nginx/conf.d/default.conf
ADD conf/nginx.conf /etc/nginx/nginx.conf
ADD conf/www.conf /etc/nginx/conf.d/www.conf

#copy supervisor config
RUN rm -rf /etc/supervisord.conf 
ADD conf/supervisord.conf /etc/supervisor/supervisord.conf

ADD scripts/start.sh /start.sh

RUN chmod 755 /start.sh

VOLUME ${document_root}

EXPOSE 80

CMD ["/start.sh"]
